<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>箭头函数</title>

</head>

<body>

    <script>

        var x=v=>v*v;

        console.log(typeof x);

        console.log(x(6));

        var ri=()=>Math.floor(Math.random()*100);//无参数的箭头函数；

        console.log(ri());

        var x2=(n1,n2)=>{

            return parseInt((n1+n2)/2);

        }

        console.log(x2(100,2));

 

        function foo()

        {

            setTimeout(()=>{console.log(this);},1000);

            setTimeout(function(){console.log(this);},1000);

        }

 

        foo();//当作function调用

        new foo();//这个是当作对象调用

        //函数体内的this对象是定义式所在的对象而不是使用时所在 对象

    </script>

</body>

</html>